﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace 学生信息管理系统
{
    public partial class TeacherSScore : Form
    {
        public TeacherSScore()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string cn_str = pub.CN_STR;
            OleDbConnection cn = new OleDbConnection(cn_str);              //建立数据库连接
            try
            {
                cn.Open();
                string select = "SELECT   *   FROM      " + this.comboBox1.Text + "   WHERE   (学号 = '" + this.txtNo.Text + "')";
                OleDbCommand cmd = new OleDbCommand(select, cn);                 //建立数据库命令
                OleDbDataReader dr = cmd.ExecuteReader();
                if (dr.Read())
                {
                    if (this.comboBox1.Text == "大一上学期")
                    {
                        this.txtName.Text = dr["姓名"].ToString();
                        this.txtGrade1.Text = dr["高等数学一"].ToString();
                        this.txtGrade2.Text = dr["大学英语一"].ToString();
                        this.txtGrade3.Text = dr["计算机科学概论"].ToString();
                        this.txtGrade4.Text = dr["c语言"].ToString();

                        this.lblGrade1.Text = "高等数学一";
                        this.lblGrade2.Text = "大学英语一";
                        this.lblGrade3.Text = "计算机科学概论";
                        this.lblGrade4.Text = "c语言";
                    }

                    else if (this.comboBox1.Text == "大一下学期")
                    {
                        this.txtName.Text = dr["姓名"].ToString();
                        this.txtGrade1.Text = dr["大学英语二"].ToString();
                        this.txtGrade2.Text = dr["高等数学二"].ToString();
                        this.txtGrade3.Text = dr["数据结构"].ToString();
                        this.txtGrade4.Text = dr["网络基础"].ToString();

                        this.lblGrade1.Text = "大学英语二";
                        this.lblGrade2.Text = "高等数学二";
                        this.lblGrade3.Text = "数据结构";
                        this.lblGrade4.Text = "网络基础";
                    }

                    else if (this.comboBox1.Text == "大二上学期")
                    {
                        this.txtName.Text = dr["姓名"].ToString();
                        this.txtGrade1.Text = dr["操作系统"].ToString();
                        this.txtGrade2.Text = dr["软件体系结构"].ToString();
                        this.txtGrade3.Text = dr["动态网页"].ToString();
                        this.txtGrade4.Text = dr["计算机网络"].ToString();

                        this.lblGrade1.Text = "操作系统";
                        this.lblGrade2.Text = "软件体系结构";
                        this.lblGrade3.Text = "动态网页";
                        this.lblGrade4.Text = "计算机网络";
                    }
                    else if (this.comboBox1.Text == "大二下学期")
                    {
                        this.txtName.Text = dr["姓名"].ToString();
                        this.txtGrade1.Text = dr["web设计"].ToString();
                        this.txtGrade2.Text = dr["概率统计"].ToString();
                        this.txtGrade3.Text = dr["马经"].ToString();
                        this.txtGrade4.Text = dr["离散数学"].ToString();

                        this.lblGrade1.Text = "web设计";
                        this.lblGrade2.Text = "概率统计";
                        this.lblGrade3.Text = "马经";
                        this.lblGrade4.Text = "离散数学";
                    }
                    else if (this.comboBox1.Text == "大三上学期") 
                    {
                        this.txtName.Text = dr["姓名"].ToString();
                        this.txtGrade1.Text = dr["操作系统"].ToString();
                        this.txtGrade2.Text = dr["组成原理"].ToString();
                        this.txtGrade3.Text = dr["java"].ToString();
                        this.txtGrade4.Text = dr["软件工程"].ToString();

                        this.lblGrade1.Text = "操作系统";
                        this.lblGrade2.Text = "组成原理";
                        this.lblGrade3.Text = "java";
                        this.lblGrade4.Text = "软件工程";
                    }

                }
                //this.GridView1.DataSource = dr;
                //this.GridView1.DataBind();
                dr.Close();
            }
            catch (Exception ex)
            {
                this.lblInfo.Text = ex.Message;
            }
            finally
            {
                cn.Close();
            }
        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            string cn_str = pub.CN_STR;
            OleDbConnection cn = new OleDbConnection(cn_str);              //建立数据库连接
            try
            {
                cn.Open();
                //忽略检测规范
                string strSql = "UPDATE  " + this.comboBox1.Text + "   SET    " + lblGrade1.Text + " = '" + txtGrade1.Text + "', " + lblGrade2.Text + "  = '" + txtGrade2.Text + "', " + lblGrade3.Text + " = '" + txtGrade3.Text + "', " + lblGrade4.Text + " = '" + txtGrade4.Text + "'   WHERE   (学号 = '" + this.txtNo.Text + "')";
                OleDbCommand cmd = new OleDbCommand(strSql, cn);                 //建立数据库命令
                OleDbDataReader dr = cmd.ExecuteReader();
                if (dr.Read())
                {
                    
                }
                MessageBox.Show("更新成功", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                dr.Close();
            }
            catch (Exception ex)
            {
                this.lblInfo.Text = ex.Message;
            }
            finally
            {
                cn.Close();
            }
        }

        private void btnInsert_Click(object sender, EventArgs e)
        {
            string cn_str = pub.CN_STR;
            OleDbConnection cn = new OleDbConnection(cn_str);              //建立数据库连接
            try
            {
                cn.Open();
                //忽略检测规范
                string strSql = "INSERT INTO   " + this.comboBox1.Text + "    (学号, 姓名," + lblGrade1.Text + " ," + lblGrade2.Text + " ," + lblGrade3.Text + " , " + lblGrade4.Text + ")   VALUES   ('" + txtNo.Text + "', '" + txtName.Text + "', '" + txtGrade1.Text + "', '" + txtGrade2.Text + "', '" + txtGrade3.Text + "', '" + txtGrade4.Text + "')";
                OleDbCommand cmd = new OleDbCommand(strSql, cn);                 //建立数据库命令
                OleDbDataReader dr = cmd.ExecuteReader();
                if (dr.Read())
                {

                }
                MessageBox.Show("添加成功", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                dr.Close();
            }
            catch (Exception ex)
            {
                this.lblInfo.Text = ex.Message;
            }
            finally
            {
                cn.Close();
            }
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            string cn_str = pub.CN_STR;
            OleDbConnection cn = new OleDbConnection(cn_str);              //建立数据库连接
            try
            {
                cn.Open();
                //忽略检测规范
                string strSql = "DELETE FROM   " + this.comboBox1.Text + "  WHERE   (学号 = '" + txtNo.Text + "')";
                OleDbCommand cmd = new OleDbCommand(strSql, cn);                 //建立数据库命令
                OleDbDataReader dr = cmd.ExecuteReader();
                if (dr.Read())
                {

                }
                MessageBox.Show("删除成功", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                dr.Close();
            }
            catch (Exception ex)
            {
                this.lblInfo.Text = ex.Message;
            }
            finally
            {
                cn.Close();
            }
        }    
    }
}
